package leetcode;

import java.util.Scanner;

/*给你一个整数 n，请你帮忙计算并返回该整数「各位数字之积」与「各位数字之和」的差。*/
public class SubtractProductAndSum {
    public static int subtractProductAndSum(int n) {
        int sum = 0;
        int product = 1;
        while (n > 0) {
            product *= n % 10;
            sum += n % 10;
            n /= 10;
        }
        return product - sum;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入一个整数: ");
        int n = scanner.nextInt();
        int result = subtractProductAndSum(n);
        System.out.println("各位数字之积与各位数字之和的差为: " + result);
        scanner.close();
    }
}
